home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / util / string / splitters.pyc (.txt) < prev   
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  125 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import re
  5. from quodlibet.util import re_escape
  6.  
  7. def split_value(s, splitters = [
  8.     '/',
  9.     '&',
  10.     ',']):
  11.     """Splits a string. The first match in 'splitters' is used as the
  12.     separator; subsequent matches are intentionally ignored."""
  13.     if not splitters:
  14.         return [
  15.             s.strip()]
  16.     values = None.split('\n')
  17.     for spl in splitters:
  18.         spl = re.compile('\\b\\s*%s\\s*\\b' % re_escape(spl), re.UNICODE)
  19.         if not filter(spl.search, values):
  20.             continue
  21.         new_values = []
  22.         for v in values:
  23.             new_values.extend([ st.strip() for st in spl.split(v) ])
  24.         
  25.         return new_values
  26.     
  27.     return values
  28.  
  29.  
  30. def find_subtitle(title):
  31.     if isinstance(title, str):
  32.         title = title.decode('utf-8', 'replace')
  33.     for pair in [
  34.         u'[]',
  35.         u'()',
  36.         u'~~',
  37.         u'--',
  38.         u'\xe3\x80\x9c\xe3\x80\x9c',
  39.         u'\xef\xbc\x88\xef\xbc\x89']:
  40.         if pair[0] in title[:-1] and title.endswith(pair[1]):
  41.             r = len(pair[1])
  42.             l = title[0:-r].rindex(pair[0])
  43.             if l != 0:
  44.                 subtitle = title[l + len(pair[0]):-r]
  45.                 title = title[:l]
  46.                 return (title.rstrip(), subtitle)
  47.         return (title, None)
  48.         return None
  49.  
  50.  
  51. def split_title(s, splitters = [
  52.     '/',
  53.     '&',
  54.     ',']):
  55.     (title, subtitle) = find_subtitle(s)
  56.     if subtitle:
  57.         return (title.strip(), split_value(subtitle, splitters))
  58.     return (None, [])
  59.  
  60. __FEATURING = [
  61.     'feat.',
  62.     'featuring',
  63.     'feat',
  64.     'ft',
  65.     'ft.',
  66.     'with',
  67.     'w/']
  68. __ORIGINALLY = [
  69.     'originally by ',
  70.     ' cover']
  71. __FEAT_REGEX = [ re.compile(re_escape(s + ' '), re.I) for s in __FEATURING ]
  72. __ORIG_REGEX = [ re.compile(re_escape(s), re.I) for s in __ORIGINALLY ]
  73.  
  74. def split_people(s, splitters = [
  75.     '/',
  76.     '&',
  77.     ',']):
  78.     (title, subtitle) = find_subtitle(s)
  79.     if not subtitle:
  80.         parts = s.split(' ')
  81.         if len(parts) > 2:
  82.             for feat in __FEATURING:
  83.                 
  84.                 try:
  85.                     i = [ p.lower() for p in parts ].index(feat)
  86.                     orig = ' '.join(parts[:i])
  87.                     others = ' '.join(parts[i + 1:])
  88.                     return (orig, split_value(others, splitters))
  89.                 continue
  90.                 except (ValueError, IndexError):
  91.                     continue
  92.                 
  93.  
  94.             
  95.         return (s, [])
  96.     old = None
  97.     for regex in __FEAT_REGEX + __ORIG_REGEX:
  98.         subtitle = re.sub(regex, '', subtitle, 1)
  99.         if old != subtitle:
  100.             break
  101.             continue
  102.     values = split_value(subtitle, splitters)
  103.     return (title.strip(), values)
  104.  
  105.  
  106. def split_album(s):
  107.     (name, disc) = find_subtitle(s)
  108.     if not disc:
  109.         parts = s.split(' ')
  110.         if len(parts) > 2:
  111.             lower = parts[-2].lower()
  112.             if 'disc' in lower or 'disk' in lower:
  113.                 return (' '.join(parts[:-2]), parts[-1])
  114.         return (s, None)
  115.     parts = None.split()
  116.     if len(parts) == 2 and parts[0].lower() in ('disc', 'disk', 'cd', 'vol', 'vol.'):
  117.         
  118.         try:
  119.             return (name, parts[1])
  120.         return (s, None)
  121.  
  122.     else:
  123.         return (s, None)
  124.  
  125.